<template>
  <div class="select-server-main">
    <el-form :inline="true" label-width="0">
      <div class="form-area">
        <el-form-item>
          <el-input v-model="search.docker_name" placeholder="服务器名称" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="search.docker_host" placeholder="服务器IP" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="search.docker_port" placeholder="服务器端口" />
        </el-form-item>
        <el-button type="primary" size="mini" @click="getServerData()" round>搜索</el-button>
      </div>
    </el-form>
    <div class="content_view">
      <el-table ref="table" :data="server_data" size="mini" stripe>
        <el-table-column label="序号" type="index" width="60" />
        <el-table-column label="服务器名称" prop="docker_name" min-width="80" align="left" />
        <el-table-column label="服务器地址" min-width="150" align="left">
          <template slot-scope="scope">
            <div>{{ scope.row.docker_host}}:{{scope.row.docker_port}}</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="80" fixed="right" align="left">
          <template slot-scope="scope">
            <el-button type="text" @click="selectServer(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { server } from '@/api/public'
export default {
  components: {},
  data() {
    return {
      search: {
        docker_name: '',
        docker_host: '',
        docker_port: ''
      },
      server_data: []
    }
  },
  watch: {
  },
  methods: {
    // 获取服务器列表
    getServerData() {
      server(this.search).then(res => {
        this.server_data = res.data
      })
    },
    // 选择服务器
    selectServer(data) {
      this.$emit('selectServer', data)
    }
  },
  created() {
    this.getServerData()
  }
}
</script>
<style lang="scss" scoped>
  .select-server-main {
    .spp-btn {
      position: relative;
      top: 3px;
    }
    .content_view{
      margin-top: 8px;
    }
    .el-form-item{
      margin: 0 !important;
    }
  }
</style>
